<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">



				<el-form-item>
					<el-input v-model="filters.dowonphonenum" placeholder="电话号码"></el-input>
				</el-form-item>


				<el-form-item label="订单状态" prop="state">
					<el-select v-model="filters.status" placeholder="号码状态">
						<el-option value="0" label="全部">全部</el-option>
						<el-option value="1" label="未充值">未充值</el-option>
						<el-option value="2" label="已充值">已充值</el-option>
					</el-select>
				</el-form-item>

				<el-form-item>
					<el-date-picker type="datetime" placeholder="开始时间"  format="yyyy-MM-dd HH:mm:ss"   v-model="filters.createTime" style="width: 100%;"></el-date-picker>
				</el-form-item>
				<el-form-item>
					<el-date-picker type="datetime" placeholder="结束时间" format="yyyy-MM-dd HH:mm:ss"   v-model="filters.endtime" style="width: 100%;"></el-date-picker>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="findPageCachePhone">查询</el-button>
				</el-form-item>

				<el-form-item>
					<el-button type="primary" v-on:click="importBroadband">导入</el-button>
				</el-form-item>

			</el-form>
		</el-col>
		<!--列表-->
		<template>
			<el-table :data="virtuals" highlight-current-row v-loading="loading" max-height="620" @selection-change="selsChange" border  style="width: 100%;">
				<el-table-column  type="selection"  width="80" label="编号">
				</el-table-column>
				<el-table-column prop="phone" label="手机号" width="170px" show-overflow-tooltip  >
				</el-table-column>
				<el-table-column prop="createTime" label="充值时间" width="170px" show-overflow-tooltip   >
				</el-table-column>
				<el-table-column prop="status" label="订单状态" show-overflow-tooltip :formatter="formatState" >
				</el-table-column>
				<!--<el-table-column label="操作"  fixed="right"   width="220">-->
					<!--<template scope="scope"   >-->
						<!--&lt;!&ndash;<el-button size="small"   @click="handleInTime(scope.$index, scope.row)">安装时间&ndash;&gt;-->
						<!--&lt;!&ndash;</el-button>&ndash;&gt;-->
						<!--&lt;!&ndash;<el-button size="small"   @click="handleEndTime(scope.$index, scope.row)">结束时间&ndash;&gt;-->
						<!--&lt;!&ndash;</el-button>&ndash;&gt;-->
						<!--<el-button size="small"   @click="handleEdit(scope.$index, scope.row)">-->
						<!--编辑-->
						<!--</el-button>-->
					<!--</template>-->
				<!--</el-table-column>-->
			</el-table>
		</template>
		<el-pagination
				@current-change="handleCurrentChange"
				@size-change="handleSizeChange"
				layout="total,sizes,prev, pager, next"
				:total="total">
		</el-pagination>


		<el-dialog title="导入订单" v-model="importFormVisible" :close-on-click-modal="false">
			<el-form :model="importForm" label-width="80px"  :inline="true":rules="importFormRules"  ref="broadband">
				<!--http://119.23.127.152:8283/weiliu/virtual/importVirtualOrder http://localhost:9899/weiliu/virtual/importVirtualOrder-->
				<el-form-item label="选择文件">
					<el-upload
							ref="importBroadbandUpload"
							action="http://119.23.127.152:8283/weiliu/virtual/importVirtualOrder"
							:limit="1"
							multiple
							:file-list="fileList"
							:beforeUpload="beforeAvatarUpload"
							:on-exceed="handleExceed"
							:on-success="handleSuccess"
							:on-preview="handlePictureCardPreview"
							:auto-upload="false"
							:on-remove="handleRemove">
						<el-button slot="trigger" size="small" type="primary">选择文件</el-button>
						<el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传到服务器</el-button>
						<div slot="tip" class="el-upload__tip">只能上传excel文件,并且单次只能上传一个文件</div>
					</el-upload>

				</el-form-item>

			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="importFormVisible=false">取消</el-button>

				<!--<el-button type="primary" @click.native="importFormSubmit" :loading="importFormLoading">提交</el-button>-->
			</div>
		</el-dialog>
	</section>

</template>
<script>
	import { findPageCachePhone ,findAllPro,findProvinceCity} from '../../api/api';
	//import NProgress from 'nprogress'
    import moment from 'moment';
    var crypto = require('crypto');
	export default {
		data() {
			return {
				filters: {
                    createTime:  moment(new Date(),"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD') + " 00:00:00",
                    endtime:'',
                    status:'',
                    phone:''
				},
                fileList: [],
                isShowSupper:JSON.parse(sessionStorage.getItem("user")).usertype === 2 ? true : false,
				start:0,
				pageSize:10,
                total:0,
				loading: false,
				users: [],
                info:[],
                citys:[],
                virtuals:[],
                sels:[],

                importFormVisible: false,
                importFormLoading: false,
                importFormRules: {
                },
                importForm: {
                    createTime: '',
                    endtime:'',
                    orderNum:'',
                    downShop:'',
                    downProduct:'',
                    errorMsg:'',
                    province:'',
                    consignee:'',
                    notifiy:'',
                    refund:'',
                    state:'',
                    amount:'',
                    useruuid:'',
                    shopRemark:'',
                    contact:''
                },
			}
		},
		methods: {

            formatState: function (row, column) {
                return row.status == 1 ? '未充值' : row.status == 2 ? '已充值' :   "未知";
            },
            findPageCachePhone: function () {
				let para = {
					start:this.start,
					pageSize:this.pageSize,
                    createTime:  moment(this.filters.createTime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD HH:mm:ss'),
                    endtime:this.filters.endtime == "" ? "" :  moment(this.filters.endtime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD HH:mm:ss'),
                    status:this.filters.status == "0" ? "" : this.filters.status,
                    phone:this.filters.phone

				};
				this.loading = true;
                findPageCachePhone(para).then(datas => {
                    this.loading = false;
                    let { message, code, data } = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.virtuals = data.result;
                        this.total = data.totalCount;
                    }
                }).catch(e =>{

				});
			},handleCurrentChange:function(val){
                this.start = val - 1;
                this.findPageCachePhone();
			},
            handleSizeChange:function(val){
			    this.pageSize = val;
			    this.findPageCachePhone();
			} ,importBroadband:function () {
                this.importFormVisible = true;
            },exportBroadband:function () {
                let para = {
                    createTime:  moment(this.filters.createTime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD HH:mm:ss'),
                    endtime:this.filters.endtime == "" ? "" :  moment(this.filters.endtime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD HH:mm:ss'),
                    orderNum:this.filters.orderNum,
                    downShop:this.filters.downShop,
                    downProduct:this.filters.downProduct,
                    province:this.filters.province == "0" ? "" : this.filters.province,
                    consignee:this.filters.consignee,
                    amount:this.filters.amount,
                    notifiy:this.filters.notifiy == "0" ? "" : this.filters.notifiy,
                    refund:this.filters.refund == "0" ? "" : this.filters.refund,
                    state:this.filters.state == "0" ? "" : this.filters.state,
                    useruuid:this.filters.useruuid == "0" ? "": this.filters.useruuid,
                    shopRemark:this.filters.shopRemark,
                    contact:this.filters.contact,
                    city : this.filters.province == "0" ? "" : this.filters.city == "0" ? "" : this.filters.city
                };
                this.loading = true;
                exportBroadband(para).then(datas => {
                    let {message, code, data} = datas;
                    this.loading = false;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        window.open(data.path);
                    }
                }).catch(e =>{
                    this.loading = false;
                });
            },importFormSubmit:function () {

            },handleRemove:function(file, fileList) {
                console.log(file, fileList);
            },
            handlePreview:function(file) {
                console.log(file);
            },
            handleExceed:function(files, fileList) {
                if(fileList.length > 1){
                    this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
				}

            },
            beforeRemove:function(file, fileList) {
                return this.$confirm(`确定移除 ${ file.name }？`);
            },handlePictureCardPreview:function(file){
                console.log(file);
			},handleSuccess:function(response, file, fileList){
                console.log(file);
                this.importFormVisible = false;
                this.findPageCachePhone();
                if(response.code == "0"){
                    this.$message({
                        message: response.message,
                        type: 'info'
                    });
				}else{
                    this.$message({
                        message: response.message,
                        type: 'warning'
                    });
				}
			},submitUpload(){
                this.$refs.importBroadbandUpload.submit();
			},beforeAvatarUpload(file){
                var testmsg=file.name.substring(file.name.lastIndexOf('.')+1)
                const extension = testmsg === 'xls';
                const extension2 = testmsg === 'xlsx';
//                const isLt2M = file.size / 1024 / 1024 < 10;
                if(!extension && !extension2) {
                    this.$message({
                        message: '上传文件只能是 xls、xlsx格式!',
                        type: 'warning'
                    });
                }

                return extension || extension2 ;
			},
            findAllPro:function(){
                let para = {useruuid: ''};
                findAllPro(para).then(datas => {
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.info = data;
                    }
                });
            },
            selectfilter:function(row){
                if(row != ""){
                    this.findProvinceCity(row)
                }
            },findProvinceCity:function (province) {
                let para = {
                    province : province
                };
                findProvinceCity(para).then((datas) => {
                    let { message, code, data } = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    }
                    this.citys = data;
                });
            } ,selsChange: function (sels) {
                this.sels = sels;
            }
		},

		mounted() {
		    this.findAllPro();
			this.findPageCachePhone();
		},
    	beforeCreate: function (){
//            window.location.reload();
		}
	};

</script>

<style scoped>

</style>
